package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.activity.manage.StartBundleKey;
import com.zlzxm.shoesmarket.view.activity.manage.bundle.BundleGoodsInfo;
import com.zlzxm.shoesmarket.view.adapter.ADSizeInfo;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityGoodsSizeInfo;
import com.zlzxm.shoesmarket.view.widget.GoodsInfoView;
import com.zlzxm.shoesmarket.viewmodel.VMGoodsSizeDetail;

import java.util.List;

/**
 * Created by zlz
 * on  4/18/21
 * <br>详情
 */
public class ACGoodsSizeDetail extends BaseActivity{


    public static void start(Context context, BundleGoodsInfo bundleGoodsInfo) {
        Intent starter = new Intent(context, ACGoodsSizeDetail.class);
        starter.putExtra(StartBundleKey.KEY_GOODS_INFO,bundleGoodsInfo);
        context.startActivity(starter);
    }

    private VMGoodsSizeDetail vmGoodsSizeDetail;

    private GoodsInfoView goodsInfoView;

    private RecyclerView recyclerView;

    private ADSizeInfo adSizeInfo = new ADSizeInfo();
    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_goods_size_detail);

        ZViewHelp.setOnClickListener(this, R.id.ivLeft, v -> finish());

        goodsInfoView = ZViewHelp.findById(this,R.id.goodsInfoView);

        recyclerView = ZViewHelp.findById(this,R.id.recyclerView);

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    protected void initViewModule() {
        super.initViewModule();

        vmGoodsSizeDetail = new ViewModelProvider(this).get(VMGoodsSizeDetail.class);

        vmGoodsSizeDetail.getLiveGoodSizeInfo().observe(this, new Observer<List<EntityGoodsSizeInfo>>() {
            @Override
            public void onChanged(List<EntityGoodsSizeInfo> entityGoodsSizeInfo) {

                adSizeInfo.setList(entityGoodsSizeInfo);
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
        recyclerView.setAdapter(adSizeInfo);
        initGoodsView();

        vmGoodsSizeDetail.requestData();
    }


    //<editor-fold defaultState="collapsed" desc="私有方法">


    private void initGoodsView(){

        BundleGoodsInfo bundleGoodsInfo = (BundleGoodsInfo) getIntent()
                .getSerializableExtra(StartBundleKey.KEY_GOODS_INFO);

        goodsInfoView.updateName(bundleGoodsInfo.getName());
        goodsInfoView.updateFace(bundleGoodsInfo.getFace());
        goodsInfoView.updateCode(bundleGoodsInfo.getCode());
        goodsInfoView.updateBrand(bundleGoodsInfo.getBrand());


    }

    // </editor-fold>

}
